#include <stdio.h>
#include <ctype.h>
#include "atom.h"

static char *atoms[MAXATOM];

atom
GetAtom(char *string)
{
    char *cp1, *cp2, upper[128];
    int i;

    for (cp1 = string, cp2 = upper; *cp1; cp1++, cp2++) {
	*cp2 = toupper(*cp1);
	if (*cp2 == '-')
	    *cp2 = '_';
    }
    *cp2 = NULL;

    for (i = 1; atoms[i] && (i < MAXATOM); i++) {
	if (strcmp(atoms[i], upper) == 0)
	    return (i);
    }
    if (i == MAXATOM) {
	fprintf(stderr, "Atom table exceeded.  Table limited to %d atoms\n",
		MAXATOM);
	return (0);
    }
    atoms[i] = (char *)strdup(upper);
    return (i);
}

char *
GetAtomVal(atom at)
{
    if (at >= MAXATOM) {
	fprintf(stderr, "Invalid atom: %d  Limit %d\n", at, MAXATOM);
	return (0);
    }
    return (atoms[at]);
}

